package com.warrior.superdata.util;

import com.alibaba.fastjson.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 分页工具类
 * @author: weiqiao.qu
 * @create: 2021/03/19 18:21
 **/
public class PageUtil {

    public static List page(List result, Integer page, Integer pageSize) {
        Integer start = (page - 1) * pageSize;
        Integer end = page * pageSize;
        if (start < result.size()) {
            return result.subList(start, Math.min(end, result.size()));
        }
        return new ArrayList();
    }

    public static List page(JSONArray result, Integer page, Integer pageSize) {
        Integer start = (page - 1) * pageSize;
        Integer end = page * pageSize;
        if (start < result.size()) {
            return result.subList(start, Math.min(end, result.size()));
        }
        return new ArrayList();
    }

}
